<extend name="_layout/main" />
<block name="head">
	<style type="text/css">
		.action_list { } fieldset {
			width: auto;
			font-size: 12px;
		}
		legend {
			width: auto;
			border: none;
			font-size: 12px;
			margin: 0;
		}
		legend label{ font-size: 12px;}
		.action_list>fieldset {
			border: 1px solid #ccc;
			padding: 0 10px 20px 10px;
			margin-bottom: 10px;
		}
		.action_list>fieldset>legend {
			padding: 0 10px;
			font-weight: bold;
			color:#666;
		}
		.action_list >fieldset fieldset {
			float: left;
			margin: 10px;
			border: 1px solid #CCC;
			padding: 10px 10px;
			display: block;
			border: 1px dotted #ccc;
			height: 65px;
		}
		.action_list >fieldset fieldset legend {
			font-weight: bold;
			border: none;
			font-size: 12px;
		}
		.action_list >fieldset fieldset label {
			margin: 0 5px;
		}
	</style>
</block>
<block name="content">
	<div class="page-content">
		<div class="page-breadcrumbs">
			<ul class="breadcrumb">
				<li>
					<i class="fa fa-home"></i>
					<a href="{:U('dashboard/index')}">系统首页</a>
				</li>
				<li>
					<a href="{:U('manager/index')}">管理中心</a>
				</li>
				<li class="active">用户组</li>
			</ul>
		</div>
		<div class="page-body">
			<div class="row">
				<div class="col-xs-12 col-md-12">
					<div class="widget">
						<div class="widget-header bordered-bottom bordered-blue">
							<span class="widget-caption">编辑用户组</span>
						</div>
						<div class="widget-body">
							<div>
								<form role="form" class="form-horizontal" id="addForm" action="{:U('manager/group_edit')}" method="post">
									<input type="hidden" name="id" value="{$id}" />
									<div class="form-group">
										<label for="name" class="col-sm-2  control-label no-padding-right">用户组名称</label>
										<div class="col-sm-4">
										<input type="text" class="form-control" id="name" name="name" value="{$name}">
										</div>
									</div>

									<div class="form-group">
										<label for="supper" class="col-sm-2  control-label no-padding-right">超级管理员</label>
										<div class="col-sm-4">
											<div class="checkbox">
											<label>
												<input type="checkbox" value="1" name="supper" id="supper" <eq name="supper" value="1">checked</eq>/>
												<span class="text"></span>
											</label>
										</div>
										</div>
									</div>

									<div class="form-group " id="purviewAction">
										<label for="name"  class="col-sm-2  control-label no-padding-right">权限列表</label>
										<div class="col-sm-8">
											<div class="action_list ">
												<volist name="purview_list" id="module">
													<fieldset>
														<legend>{$module['name']}</legend>
														<volist name="module.child" id="cmodule">
															<fieldset class="pur_block">
																<legend>
																		<label>
																		<input type="checkbox" class="selectall">
																		<span class="text">{$cmodule['name']}</span>
																	</label>
																</legend>
																<volist name="cmodule.action_list" id="action">
																	
																	<label>
																		<input type="checkbox"  name="purview_id[]" value="{$action['id']}"} <in name="action.id" value="$purview">checked</in> />
																		<span class="text">{$action['name']}</span>
																	</label>
																</volist>
															</fieldset>
														</volist>
													</fieldset>
												</volist>
											</div>
										</div>
									</div>
									<div class="form-group">
                                                        <div class="col-sm-offset-2 col-sm-10">
                                                            <button type="submit" class="btn btn-danger">确认保存</button>
                                                        </div>
                                                    </div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</block>

<block name="footer">
	<script src="/Public/assets/js/validation/bootstrapValidator.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">
var id = {$id};
	$("#supper").change(function(){ 
		if($(this).prop("checked")){ 
			$("#purviewAction").hide();
		}else{ 
			$("#purviewAction").show();
		}
	});
	$(".selectall").change(function(){ 
		if($(this).prop("checked")){ 
			$(this).parents(".pur_block").find("input[name='purview_id[]']").prop("checked",true);
		}
	});
	$("#addForm").bootstrapValidator({              
	                excluded: [':disabled'],
	                feedbackIcons: {
	                    valid: 'glyphicon glyphicon-ok',
	                    invalid: 'glyphicon glyphicon-remove',
	                    validating: 'glyphicon glyphicon-refresh'
	                },
	                submitHandler: function (validator, form, submitButton) {
	                    validator.defaultSubmit();
	                },
	                fields: {
	                    name: {
	                        validators: {
	                            notEmpty: {
	                                message: '用户组名称不能为空'
	                            },
	                             remote: {
				                        message: '用户组名称已经存在',
				                        url: '{:U('manager/group_unique')}',
				                        data:{ 
				                        	id:id
				                        }
				                    }
	                        }
	                    }
	                }
	            });
	
</script>
</block>